<%@ page language="java" import="java.util.*" pageEncoding="Utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!--我的订单页面 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>我发布的二货 - 二手网</title>
<link href="css/order_my.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-2.1.1.js"></script>
<style type="text/css">
.page-input{
	width:40px;
	height: 20px;
	line-height: 20px;
	padding-left: 5px;
	border-radius: 5px;
	border:1px solid #ccc;
	outline: none;
}
.page-btn{
	width:40px;
	height: 28px;
	line-height: 20px;
	padding-left: 5px;
	border-radius: 5px;
	border: none;
	color:#fff;
	background: #6CB98F;
}
</style>
</head>
<body>
  <div id="nav">
     <span>您的位置： </span>
     <span style="color:#16a085">我发布的二货</span>
  </div>
  <div id="content">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
<thead>
  <tr>
    <td class="goods" colspan="2">商品</td>
    <td class="goods">单价（元）</td>
    <td class="goods">库存</td>
    <td class="goods">发布时间</td>
    <td class="goods">操作</td>
  </tr>
 </thead>
 <tbody id="bod_data"></tbody>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0"  >

<tr id="content">

</tr>

</table>
	<table align="center" width=55%>
   	<tr>
   		<td><a id="firstpage" style="cursor: pointer;">首页</a></td>
   		<td><a id="prepage" style="cursor: pointer;">上一页</a></td>
   		<td><a id="nextpage" style="cursor: pointer;">下一页</a></td>
   		<td><a id="lastpage" style="cursor: pointer;">末页</a></td>
   		<td>当前页:<span id="currenpage"></span>/<span id="totalpage"></span></td> 
   	</tr>
   	</table>
</div>
</body>
<script src="js/liu.js"></script>
<script type="text/javascript">

	

	
	$(function(){
		//进去页面先查询数据
		$.ajax({
			type:"POST",
			url:"MyProduct.action?method=myProducts",
			data:{"currPage":1},
			success:function(response,status,xhr){
         		var page=xhr.responseText;
				var pagedata=eval('('+page+')');
				$("#currenpage").html(pagedata.currenpage);
				$("#totalpage").html(pagedata.totalpage);
				for(var i=0;i<pagedata.data.length;i++){
					$("#bod_data").append("<tr><td class='goods order_item_select' colspan='2' style='text-align:center;'><a>"+pagedata.data[i].goodsId+"</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+pagedata.data[i].goodsName+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsPrice+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsNumber+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].issueTime+"</td><td class='goods order_item_select' style='text-align:center;'><lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='updateRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>编辑</lable>&nbsp;&nbsp;&nbsp;<lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='deleteRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>删除</lable></tr>");
				}
         	}
		});
		//点击首页
		$("#firstpage").click(function(){
			var currenpagedata=parseInt($("#currenpage").html());
			if(currenpagedata!=1){
			$.ajax({
					type:"POST",
					url:"MyProduct.action?method=myProducts",
					data:{"currPage":1},
					success:function(response,status,xhr){
						var page=xhr.responseText;
						var pagedata=eval('('+page+')');
						$("#currenpage").empty();
						$("#currenpage").html(pagedata.currenpage);
						$("#bod_data").empty();
						for(var i=0;i<pagedata.data.length;i++){
							$("#bod_data").append("<tr><td class='goods order_item_select' colspan='2' style='text-align:center;'><a>"+pagedata.data[i].goodsId+"</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+pagedata.data[i].goodsName+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsPrice+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsNumber+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].issueTime+"</td><td class='goods order_item_select' style='text-align:center;'><lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='updateRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>编辑</lable>&nbsp;&nbsp;&nbsp;<lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='deleteRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>删除</lable></tr>");
						}
					}
			});
		}
			
	});
		//点击末页
		$("#lastpage").click(function(){
			var currenpagedata=parseInt($("#currenpage").html());
			var totalpagedata=parseInt($("#totalpage").html());
			if(currenpagedata!=totalpagedata){
				$.ajax({
					type:"POST",
					url:"MyProduct.action?method=myProducts",
					data:{"currPage":totalpagedata},
					success:function(response,status,xhr){
						var page=xhr.responseText;
						var pagedata=eval('('+page+')');
						
						$("#currenpage").empty();
						$("#currenpage").html(pagedata.currenpage);
						$("#bod_data").empty();
						for(var i=0;i<pagedata.data.length;i++){
							$("#bod_data").append("<tr><td class='goods order_item_select' colspan='2' style='text-align:center;'><a>"+pagedata.data[i].goodsId+"</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+pagedata.data[i].goodsName+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsPrice+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsNumber+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].issueTime+"</td><td class='goods order_item_select' style='text-align:center;'><lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='updateRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>编辑</lable>&nbsp;&nbsp;&nbsp;<lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='deleteRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>删除</lable></tr>");
						}
					}
				});
			}
			
	});
		//点击下一页
		
		$("#nextpage").click(function(){
			var currenpagedata=parseInt($("#currenpage").html());
			var totalpagedata=parseInt($("#totalpage").html());
			if(currenpagedata<totalpagedata){
				currenpagedata=currenpagedata+1;
				$.ajax({
					type:"POST",
					url:"MyProduct.action?method=myProducts",
					data:{"currPage":currenpagedata},
					success:function(response,status,xhr){
						var page=xhr.responseText;
						var pagedata=eval('('+page+')');
						
						$("#currenpage").empty();
						$("#currenpage").html(pagedata.currenpage);
						$("#bod_data").empty();
						for(var i=0;i<pagedata.data.length;i++){
							$("#bod_data").append("<tr><td class='goods order_item_select' colspan='2' style='text-align:center;'><a>"+pagedata.data[i].goodsId+"</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+pagedata.data[i].goodsName+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsPrice+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsNumber+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].issueTime+"</td><td class='goods order_item_select' style='text-align:center;'><lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='updateRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>编辑</lable>&nbsp;&nbsp;&nbsp;<lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='deleteRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>删除</lable></tr>");
						}
					}
				});
			}else{
				currenpage=totalpage;
			}
		});
		//点击上一页
		
		$("#prepage").click(function(){
			var currenpagedata=parseInt($("#currenpage").html());
			var totalpagedata=parseInt($("#firstpage").html());
			if(currenpagedata>1){
				currenpagedata=currenpagedata-1;
				$.ajax({
					type:"POST",
					url:"MyProduct.action?method=myProducts",
					data:{"currPage":currenpagedata},
					success:function(response,status,xhr){
						var page=xhr.responseText;
						var pagedata=eval('('+page+')');
						
						$("#currenpage").empty();
						$("#currenpage").html(pagedata.currenpage);
						$("#bod_data").empty();
						for(var i=0;i<pagedata.data.length;i++){
							$("#bod_data").append("<tr><td class='goods order_item_select' colspan='2' style='text-align:center;'><a>"+pagedata.data[i].goodsId+"</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+pagedata.data[i].goodsName+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsPrice+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].goodsNumber+"</td><td class='goods order_item_select' style='text-align:center;'>"+pagedata.data[i].issueTime+"</td><td class='goods order_item_select' style='text-align:center;'><lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='updateRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>编辑</lable>&nbsp;&nbsp;&nbsp;<lable style='text-decoration:none;cursor:pointer;color:#5cbdaa' onclick='deleteRow("+pagedata.currenpage+","+pagedata.data[i].goodsId+");'>删除</lable></tr>");
						}
					}
				});
			}else{
				currenpage=firstpage+1;
			}
		});
	});
	
	
function deleteRow(curren,goodid){
    	var url="deleteById.action?method=deletes&curren="+curren+"&id="+goodid;
    	if(confirm("确定要删除吗？")){
    		window.location=url;
    	}
        	
    }
    function updateRow(curren,goodid){
    	window.location="update.action?method=modify&id="+goodid;
    	
    	
    	}
        	
    
	</script>
</html>